package com.example.jksj.bookmanagement.utils;
/*
 *  项目名：    SmartButler
 *  包名：      com.imooc.smartbutler.utils
 *  文件名:     ShareUtils
 *  创建者:     HXD
 *  创建时间:   2018/11/18 14:07
 *  描述:       SharedPreferences封装工具类
 */

import android.content.Context;
import android.content.SharedPreferences;
import android.support.annotation.Nullable;

import com.example.jksj.bookmanagement.Base.BaseApplication;


public class ShareUtils {

    private static String NAME = "BookManagement";
    private static SharedPreferences SP =  BaseApplication.getContext().getSharedPreferences(NAME, Context.MODE_PRIVATE);;

    public static void setSPName( @Nullable String name){
        if (name != null){
            SP = BaseApplication.getContext().getSharedPreferences(name, Context.MODE_PRIVATE);
        }
    }

    //键 值
    public static void putString(String key, String value){
        SP.edit().putString(key, value).commit();
    }

    //键 默认值
    public static String getString(String key, String defValue){
        return SP.getString(key, defValue);
    }

    //键 值
    public static void putInt(String key, int value){
        SP.edit().putInt(key, value).commit();
    }

    //键 默认值
    public static int getInt(String key, int defValue){
        return SP.getInt(key, defValue);
    }

    //键 值
    public static void putBoolean(String key, boolean value){
        SP.edit().putBoolean(key, value).commit();
    }

    //键 默认值
    public static boolean getBoolean(String key, boolean defValue){
        return SP.getBoolean(key, defValue);
    }

    //键 值
    public static void putFloat(String key, float value){
        SP.edit().putFloat(key, value).commit();
    }

    //键 默认值
    public static float getFloat(String key, float defValue){
        return SP.getFloat(key, defValue);
    }

    //删除单个键值对
    public static void deletedShare(String key){
        SP.edit().remove(key).commit();
    }

    //删除全部
    public static void deletedAll(){
        SP.edit().clear().commit();
    }
}
